package com.andnux.android.network;

import com.andnux.android.MainApp;
import com.andnux.android.data.SystemUsers;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class HttpTokenInterceptor implements Interceptor {

    @NotNull
    @Override
    public Response intercept(Chain chain) throws IOException {
        SystemUsers users = MainApp.getApp().getSystemUsers();
        Request originalRequest = chain.request();
        if (users == null || users.getId() == 0) {
            return chain.proceed(originalRequest);
        } else {
            Request request = originalRequest.newBuilder()
                    .header("userId", String.valueOf(users.getId()))
                    .build();
            return chain.proceed(request);
        }
    }
}
